Completed
Push — master ( a00f3d...6cfb01 )
by greg
01:46
created

manager.js ➔ describe(ꞌManagerꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 68

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
nc 1
dl 0
loc 68
rs 9.2447
c 2
b 1
f 0
nop 0

9 Functions

Rating   Name   Duplication   Size   Complexity  
A manager.js ➔ ... ➔ it(ꞌupdatePostInList() with new postꞌ) 0 11 1
A manager.js ➔ ... ➔ it(ꞌgetListWithStatusOnFolder() status reviewꞌ) 0 4 1
A manager.js ➔ ... ➔ it(ꞌgetList()ꞌ) 0 5 1
A manager.js ➔ ... ➔ it(ꞌgetListWithStatusOnFolder() status publishꞌ) 0 5 1
A manager.js ➔ ... ➔ before 0 13 1
A manager.js ➔ ... ➔ it(ꞌgetListWithStatusOnFolder() status publish /0-1ꞌ) 0 5 1
A manager.js ➔ ... ➔ it(ꞌgetStructureAndTemplates()ꞌ) 0 5 1
A manager.js ➔ ... ➔ it(ꞌgetListWithStatusOnFolder() status draftꞌ) 0 4 1
A manager.js ➔ ... ➔ it(ꞌupdateStructureAndTemplates()ꞌ) 0 6 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var chai = require('chai');
2
var path = require('path');
3
4
var Manager = require('../src/cli').Manager
5
var config = require('../src/cli').config
6
var cmsOperations = require('../src/cli').cmsOperations
7
config.set({root: __dirname + '/fixtures/'})
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
8
9
var cmsData = require('../src/cli').cmsData;
10
var Manager = require('../src/cli').Manager;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable Manager already seems to be declared on line 4. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
11
var fse = require('fs-extra');
12
13
describe('Manager', function() {
14
  before( function(done) {
15
    Manager.instance.init()
16
      .then(function () {
17
18
        this.fixture = {
19
          tag: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
20
          jsonArticle: fse.readJsonSync(__dirname + '/fixtures/files/article-4.json'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
21
          jsonArticle1: fse.readJsonSync(__dirname + '/fixtures/data/article-1.json')
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
22
        }
23
        done()
24
        
25
      }.bind(this))
26
  });
27
28
  it('getStructureAndTemplates()', function() {
29
    const data = Manager.instance.getStructureAndTemplates()
30
    chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !')
31
    chai.assert.equal(data['templates'].length, 7, 'failed !')
32
  });
33
34
  it('updateStructureAndTemplates()', function() {
35
    Manager.instance.updateStructureAndTemplates()
36
    const data = Manager.instance.getStructureAndTemplates()
37
    chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !')
38
    chai.assert.equal(data['templates'].length, 7, 'failed !')
39
  });
40
41
  it('getList()', function() {
42
    const list = Manager.instance.getList()
43
    chai.assert.equal(list[0].name, 'article-1.json', 'failed !')
44
    chai.assert.equal(list.length, 3, 'failed !')
45
  });
46
47
  it('getListWithStatusOnFolder() status publish', function() {
48
    const list = Manager.instance.getListWithStatusOnFolder('publish')
49
    chai.assert.equal(list[0].name, 'article-1.json', 'failed !')
50
    chai.assert.equal(list.length, 2, 'failed !')
51
  });
52
53
  it('getListWithStatusOnFolder() status draft', function() {
54
    const list = Manager.instance.getListWithStatusOnFolder('draft')
55
    chai.assert.equal(list.length, 2, 'failed !')
56
  });
57
58
  it('getListWithStatusOnFolder() status review', function() {
59
    const list = Manager.instance.getListWithStatusOnFolder('review')
60
    chai.assert.equal(list.length, 0, 'failed !')
61
  });
62
63
  it('getListWithStatusOnFolder() status publish /0-1', function() {
64
    const list = Manager.instance.getListWithStatusOnFolder('draft', '0-1')
65
    chai.assert.equal(list[0].name, 'article-2.json', 'failed !')
66
    chai.assert.equal(list.length, 1, 'failed !')
67
  });
68
69
  it('updatePostInList() with new post', function(done) {
70
    const len = Manager.instance.getList().length
71
    cmsOperations.create('article', '', 'article-4.html', {query: ''}, this.fixture.jsonArticle, false)
72
      .then(function(resSave) {
73
        const json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json'))
74
        const list = Manager.instance.getList()
75
        fse.removeSync(json)
76
        chai.assert.equal(list.length, len + 1, 'failed !')
77
        done()
78
      }.bind(this));
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
79
  });
80
});
81